home *** CD-ROM | disk | FTP | other *** search
Wrap
# Source Generated with Decompyle++ # File: in.pyc (Python 2.6) import sys import apt import apt_pkg import gettext import aptsources.distro as aptsources import Parser import Helpers from aptsources.sourceslist import SourcesList, is_mirror from optparse import OptionParser from gettext import gettext as _ import os import os.path as os allow_new_repositories = False channelsdir = '/usr/share/app-install/channels' (RESULT_OK, RESULT_CANCELT, RESULT_ERROR, RESULT_BADARGS) = range(4) class AptUrlController(object): def __init__(self, ui): self.ui = ui def enableSection(self, apturl): added = False sourceslist = SourcesList() distro = aptsources.distro.get_distro() distro.get_sources(sourceslist) requested_components = [] for component in apturl.section: if component not in distro.enabled_comps and not self.cache.has_key(apturl.package): requested_components.append(component) continue if not requested_components: return RESULT_OK if not self.ui.askEnableSections(apturl.section): return RESULT_CANCELT if not self.ui.doEnableSection(apturl.section): self.ui.error(_("Enabling '%s' failed") % ', '.join(apturl.section)) return RESULT_ERROR self.ui.doUpdate() self.openCache() return RESULT_OK def enableChannel(self, apturl): channel = os.path.basename(apturl.channel) channelpath = '%s/%s.list' % (channelsdir, channel) channelkey = '%s/%s.key' % (channelsdir, channel) if not os.path.exists(channelpath): self.ui.error(_("Unknown channel '%s'") % channel, _("The channel '%s' is not known") % channel) return RESULT_ERROR if not self.ui.askEnableChannel(apturl.channel): return RESULT_CANCELT if not self.ui.doEnableChannel(channelpath, channelkey): self.ui.error(_("Enabling channel '%s' failed") % apturl.channel) return RESULT_ERROR self.ui.doUpdate() self.openCache() return RESULT_OK def openCache(self): try: self.cache = apt.Cache() except SystemError: strerr = None if '/etc/apt/sources.list' not in str(strerr): raise '/etc/apt/sources.list' not in str(strerr) self.ui.error(_('Invalid /etc/apt/sources.list file'), strerr) return False if self.cache._depcache.BrokenCount > 0: err_header = _('Software index is broken') err_body = _("This is a major failure of your software management system. Please check for broken packages with synaptic, check the file permissions and correctness of the file '/etc/apt/sources.list' and reload the software information with: 'sudo apt-get update' and 'sudo apt-get install -f'.") self.ui.error(err_header, err_body) return False return True def parseArgs(self): parser = OptionParser() parser.add_option('-p', '--http-proxy', dest = 'http_proxy', default = None, help = 'use http proxy') (options, args) = parser.parse_args() if options.http_proxy is not None: proxy = options.http_proxy if ':' not in proxy: proxy += ':3128' os.environ['http_proxy'] = 'http://%s' % proxy try: apturl_list = Parser.parse(args[0]) except IndexError: e = None self.ui.error(_('Need a url to continue, exiting')) return [] except Parser.InvalidUrlException: e = None self.ui.error(_("Invalid url: '%s' given, exiting") % sys.argv[1], '%s' % e) return [] else: return apturl_list def verifyInstall(self, apturl): ''' verify that the install package actually is installed ''' self.openCache() pkg = self.cache[apturl.package] if not (pkg.isInstalled) and pkg._pkg.CurrentState != apt_pkg.CurStateInstalled or self.cache._depcache.BrokenCount > 0: return False return True def main(self): ret = RESULT_OK ui = self.ui apturl_list = self.parseArgs() if not apturl_list: return RESULT_BADARGS if not self.openCache(): return RESULT_ERROR for apturl in apturl_list: if apturl.section: if self.enableSection(apturl) != RESULT_OK: continue elif apturl.channel: if self.enableChannel(apturl) != RESULT_OK: continue elif apturl.refresh is not None: ui.doUpdate() if not self.openCache(): return RESULT_ERROR if not self.cache.has_key(apturl.package): try: package_in_cache = bool(self.cache._cache[apturl.package]) except KeyError: package_in_cache = False if package_in_cache: ui.error(_("Package '%s' is virtual.") % apturl.package) continue else: ui.error(_("Could not find package '%s'.") % apturl.package) if self.cache[apturl.package].isInstalled and apturl.minver is None: ui.message(_("Package '%s' is already installed") % apturl.package) continue pkg = self.cache[apturl.package] (sum, desc, homepage) = Helpers.parse_pkg(pkg) if not ui.askInstallPackage(apturl.package, sum, desc, homepage): ret = RESULT_CANCELT continue try: self.cache[apturl.package].markInstall() except SystemError: e = None ui.error(_("Can not install '%s' (%s) ") % (apturl.package, e)) continue if apturl.minver is not None: verStr = self.cache[apturl.package].candidateVersion if apt_pkg.VersionCompare(verStr, apturl.minver) < 1: ui.error(_("Package '%s' requests minimal version '%s', but only '%s' is available") % (apturl.package, apturl.minver, verStr)) continue ui.doInstall(apturl) if not self.verifyInstall(apturl): ret = RESULT_ERROR continue return ret